﻿using DiffuseEnjoyIdle.IService;
using Hangfire;
using Microsoft.Extensions.DependencyInjection;

namespace DiffuseEnjoyIdle.TimedTaskCentre.Hangfire.Job
{
    public class TestJob : IHangfireJob
    {
        private readonly IServiceProvider _serviceProvider;
        private readonly IUserService _userService;
        public TestJob(IServiceProvider serviceProvider, IUserService userService)
        {

            _serviceProvider = serviceProvider;
            _userService= userService;
        }

        public async Task ExecuteAsync()
        {
            using var scope = _serviceProvider.CreateScope();
            var service = scope.ServiceProvider.GetRequiredService<IUserService>();  
            RecurringJob.AddOrUpdate(  () =>   service.Test(), Cron.Minutely);
        }
    }
}
